from flask import Flask
from .config import Config
from app.extensions import db
from app.routes import register_blueprints
from flask_cors import CORS
def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = False  # 避免自动提交/回滚
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db.init_app(app)
    
    # 先注册蓝图
    register_blueprints(app)
    
    # 最后初始化CORS（关键！）
    CORS(app)
    
    return app